#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>

using namespace std;

bool only07(int n)
{
  vector<char> ns;

  while(n != 0)
  {
    ns.push_back(n % 10 + '0');
    n /= 10;
  }

  for(char c : ns)
  {
    if(!(c == '0' || c == '7'))
    {
      return false;
    }
  }
  
  return true;
}

int result07(int n)
{
  int i = 2;

  while (!only07(i * n))
  {
    i += 1;
  }

  return i * n;
}

bool isPalindrome(int n)
{
  string ns = to_string(n);
  string nsCopy = ns;
  reverse(nsCopy.begin(), nsCopy.end());
  return ns == nsCopy;
}

int result07_1(int n)
{
  int i = 2;
  while (stoi(bitset<16>(i).to_string()) * 7 % n != 0)
  {
    ++i;
  }
  return stoi(bitset<16>(i).to_string()) * 7;
}

int main(int argc, char const *argv[])
{
  cout << result07_1(9) << endl;
  return 0;
}
